<?php
require_once ('AppModel.php');



/**
 * @author Windows 8 Pro User
 * @version 1.0
 * @created 02-dez-2013 23:26:30
 */
class User extends AppModel
{

	/**
	 * Set the model name
	 */
	public $name = 'User';
	/**
	 * Set the model validation
	 */
	public $validate = array(
		'username' => array(
			'required' => array(
				'rule' => array('notEmpty'),
				'message' => 'Login requerido'
			)
		),
		'password' => array(
			'required' => array(
				'rule' => array('notEmpty'),
				'message' => 'Senha requerida'
			)
		),
		'role' => array(
			'valid' => array(
				'rule' => array('inList', array('admin', 'author')),
				'message' => 'Por favor esconha um acesso válido',
				'allowEmpty' => false
			)
		),												
		'email' => array(
			'required' => array(
				'rule' => array('email'),
				'message' => 'Por favor digite um e-mail válido',
			)
		)
	);

	/**
	 * 
	 * @param options
	 */
	public function beforeSave($options = array())
	{
		// Get the password before it saves
		if (isset($this->data[$this->alias]['password'])) {
			// Encrypt the password
			$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
		}
		
		// Provide the return
		return true;
	}

}
?>